<template>
  <div>
    <section class="header clearfix">
      <span>个体管理</span>
      <span class="iconfont iconadd1" v-if="isShow" @click="add"> 添加</span>
    </section>
    <div class="search-box" @keyup.enter="searchFun">
      <i class="iconfont iconsearch1"></i>
      <el-input
        placeholder="输入姓名进行搜索"
        class="search"
        v-model.trim="searchContent"
      ></el-input>
    </div>
    <div class="search-box search-box-last">
      <section class="option">
        <span>状态:</span>
        <el-select
          v-model="isStopCompany"
          @change="statusChange"
          placeholder="请选择"
        >
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </section>
    </div>
    <div class="table">
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        v-loading="loading"
        style="width: 100%"
      >
        <el-table-column
          prop="companyName"
          fixed
          label="姓名"
        ></el-table-column>
        <el-table-column
          prop="isStopCompany"
          label="状态"
          :formatter="statusFormatter"
        ></el-table-column>
        <!-- <el-table-column label="账户信息">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="balance(scope.row.accountId, scope.row.companyId)"
              >查看</el-button
            >
          </template>
        </el-table-column>

        <el-table-column label="账户流水" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" @click="accountCome(scope.row)"
              >进入</el-button
            >
          </template>
        </el-table-column> -->

        <el-table-column label="个人信息" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" @click="employeeList(scope.row)"
              >进入</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="区域缴纳" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" @click="setArea(scope.row.companyId)"
              >设置</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="订单列表" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" @click="billList(scope.row)">查看</el-button>
          </template>
        </el-table-column>
        <el-table-column label="详情" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" @click="look(scope.row.companyId)"
              >查看</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" v-if="isShow">
          <template slot-scope="scope">
            <el-button
              type="danger"
              size="mini"
              v-if="scope.row.isStopCompany == 0"
              @click="stop(scope.row.companyId)"
              >停用</el-button
            >
            <el-button
              v-else
              size="mini"
              type="primary"
              @click="start(scope.row.companyId)"
              >启用</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="current"
        :page-sizes="[6, 12, 24, 36]"
        :page-size="pageSize"
        layout="sizes, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
    
    <el-dialog
      title="账户信息"
      :visible.sync="operateDialog"
      width="500px"
      center
    >
      <section class="message">
        <span>账户余额：</span
        ><span
          ><i class="sign">￥</i>{{ balanceInfo.balance | moneyFilters }}</span
        >
      </section>
      <section class="message">
        <span>充值冻结：</span
        ><span
          ><i class="sign">￥</i
          >{{ balanceInfo.rechargeFreeze | moneyFilters }}</span
        >
      </section>
      <section class="message">
        <span>提现冻结：</span
        ><span
          ><i class="sign">￥</i
          >{{ balanceInfo.withdrawalFreeze | moneyFilters }}</span
        >
      </section>
      <section class="message">
        <span>支出冻结：</span
        ><span
          ><i class="sign">￥</i
          >{{ balanceInfo.consumeFreeze | moneyFilters }}</span
        >
      </section>

      <div slot="footer" class="dialog-footer">
        <el-button
          @click="
            operateDialog = false;
            payLoading = false;
          "
          >取 消</el-button
        >
        <el-button type="primary" @click="payApply">充值申请</el-button>
        <el-button type="primary" @click="expenditureApply">支出申请</el-button>
      </div>
    </el-dialog>
    <!--申请-->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false"
      :show-close="false"
      center
    >
      <el-form>
        <el-form-item label="金额" :label-width="formLabelWidth" required>
          <el-input
            placeholder="输入金额"
            class="search"
            v-model.trim="amount"
          ></el-input>
        </el-form-item>
        <el-form-item label="备注" :label-width="formLabelWidth">
          <el-input
            placeholder="输入备注"
            class="search"
            v-model.trim="remarks"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          @click="
            dialogFormVisible = false;
            payLoading = false;
          "
          >取 消</el-button
        >
        <el-button type="primary" :loading="payLoading" @click="comfirm()"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template> 

<script>
import base from "@/assets/js/base";
import { requestApiPost } from "../api/api";
import { reqRep } from "../report/reqReport";
import { resRep } from "../report/resReport";
export default {
  name: "personageManagement",
  data() {
    return {
      amount: "",
      remarks: "",
      dialogTitle: "",
      formLabelWidth: "160px",
      dialogFormVisible: false,
      payLoading: false,
      isShow: false,
      loading: false,
      isSelect: false,
      operateDialog: false,
      isNumber: 0,
      searchContent: "",
      isStopCompany: "2",
      tableData: [],
      balanceInfo: {},
      multipleSelection: [],
      current: 1,
      pageSize: 6,
      total: null,
      statusOptions: [
        {
          label: "所有",
          value: "2",
        },
        {
          label: "停用",
          value: "1",
        },
        {
          label: "正常",
          value: "0",
        },
      ],
    };
  },
  methods: {
    payApplyRequest() {
      var reqData = {
        amount: this.amount,
        remarks: this.remarks,
        accountId: this.accountId,
      };
      let reqReport = reqRep({ traCode: "_INVEST_APPLY_ACC", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
          this.payLoading = false;
        } else {
          this.$message({
            message: "成功",
            type: "success",
          });

          this.dialogFormVisible = false;
          this.payLoading = false;
        }
      });
    },
    expenditureApplyRequest() {
      var reqData = {
        amount: this.amount,
        remarks: this.remarks,
        accountId: this.accountId,
      };
      let reqReport = reqRep({ traCode: "_PAY_APPLY_ACC", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
          this.payLoading = false;
        } else {
          this.$message({
            message: resReport.getReMsg(),
            type: "success",
          });

          this.dialogFormVisible = false;
          this.payLoading = false;
        }
      });
    },
    comfirm() {
      if (!this.amount || this.amount <= 0) {
        this.$message.warning("请输入正确的金额");
        return;
      }
      this.payLoading = true;
      if (this.dialogTitle == "充值申请") {
        this.payApplyRequest();
      } else {
        this.expenditureApplyRequest();
      }
    },
    payApply() {
      this.amount = "";
      this.remarks = "";
      this.dialogTitle = "充值申请";
      this.dialogFormVisible = true;
    },
    expenditureApply() {
      this.amount = "";
      this.remarks = "";
      this.dialogTitle = "支出申请";
      this.dialogFormVisible = true;
    },
    statusChange() {
      this.getData();
    },
    handleSizeChange(e) {
      this.pageSize = e;
      this.getData();
    },
    handleCurrentChange(e) {
      this.current = e;
      this.getData();
    },
    paymentSchedule(obj) {
      sessionStorage.setItem("paymentCompanyId", obj.id);
      sessionStorage.setItem("paymentCompanyName", obj.companyName);
      setTimeout(() => {
        this.$router.push("paymentSchedules");
      }, 200);
    },
    look(companyId) {
      this.$router.push({
        path: "/editIndividual",
        query: { companyId: companyId },
      });
    },
    //账户余额
    balance(accountId, operationId) {
      this.operateDialog = true;
      this.balanceInfo = {};
      var reqData = {
        accountId: accountId,
        operationId: operationId,
        operationType: 0,
      };
      let reqReport = reqRep({ traCode: "_GET_ACC_BALANCE", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.balanceInfo = resReport.data;
          this.operateDialog = true;
        }
      });
    },
    //账户流水
    accountCome(item) {
      this.$router.push({
        path: "/balanceList",
        query: { OName: item.companyName, accountId: item.accountId },
      });
    },
    //停用个体
    stop(companyId) {
      this.$confirm("确定停用该个体?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.stopCompany(companyId);
        })
        .catch(() => {});
    },
    stopCompany(companyId) {
      var reqData = {
        companyId: companyId,
      };
      let reqReport = reqRep({ traCode: "_STOP_COMPANY", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.$message({
            message: "停用成功",
            type: "success",
          });
          this.getData();
        }
      });
    },
    //启用个体
    start(companyId) {
      this.$confirm("确定启用该个体?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.startCompany(companyId);
        })
        .catch(() => {});
    },
    startCompany(companyId) {
      var reqData = {
        companyId: companyId,
      };
      let reqReport = reqRep({ traCode: "_START_COMPANY", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.$message({
            message: "启用成功",
            type: "success",
          });
          this.getData();
        }
      });
    },
    employeeList(obj) {
      sessionStorage.setItem("personage", JSON.stringify(obj));
      setTimeout(() => {
        this.$router.push({
          path: "/employeesList",
          query: {
            companyName: obj.companyName,
            companyId: obj.companyId,
            hide: 1,
          },
        });
      }, 200);
    },
    billList(obj) {
      sessionStorage.setItem("paymentCompanyName", obj.companyName);
      setTimeout(() => {
        this.$router.push("billList");
      }, 200);
    },
    setArea(companyId) {
      this.$router.push({
        path: "/payZoneList",
        query: { companyId: companyId },
      });
    },
    jumpPage(name) {
      this.$router.push(name);
    },
    //添加个体
    add() {
      this.$router.push("addIndividual");
    },
    searchFun() {
      this.current = 1;
      this.tableData = [];
      this.getData();
    },
    //获取个体列表
    getData() {
      this.loading = true;
      var reqData = {
        infoType: "1",
        isStopCompany: this.isStopCompany,
        companyName: this.searchContent,
        current: this.current,
        pageSize: this.pageSize,
      };
      let reqReport = reqRep({ traCode: "_LIST_COMPANY", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        this.loading = false;
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.tableData = resReport.data.records;
          this.total = parseInt(resReport.data.total);
        }
      });
    },
    statusFormatter(a, b, c) {
      if (c == 0) {
        return "正常";
      } else if (c == 1) {
        return "停用";
      }
    },
  },
  created() {
    if (
      sessionStorage.getItem("KEY") == "A" ||
      sessionStorage.getItem("KEY") == "O"
    ) {
      this.isShow = true;
    } else {
      this.isShow = false;
    }
    this.getData();
  },
  mounted() {
    sessionStorage.removeItem("personage");
  },
};
</script>
<style scoped>
.header {
  padding: 15px;
  height: 50px;
  box-sizing: border-box;
  font-size: 14px;
}
.header .org {
  float: right;
  cursor: pointer;
}
.org:hover {
  color: #13cb6e;
}
.header i {
  font-size: 20px;
  margin-right: 5px;
}
.opt-user {
  padding: 20px 15px;
}
.opt-user > section {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}
.opt-user i {
  font-size: 20px;
  margin-right: 5px;
  vertical-align: middle;
}
.iconadd1 {
  float: right;
  font-size: 14px;
  color: #13cb6e;
  cursor: pointer;
}
.search-box {
  height: 50px;
  line-height: 50px;
  border-top: 1px solid #eee;
  border-bottom: 1px solid #eee;
}
.search-box-last {
  border-top: none;
}
.search-box i {
  margin-left: 15px;
  vertical-align: middle;
}
.search-box .search {
  display: inline-block;
  width: 360px;
}
.search-box .option {
  display: inline-block;
  margin-left: 15px;
}
.search-box .el-select {
  width: 150px;
}
.search-box .el-select input {
  min-width: 100px;
  background-color: #eee;
}
.search-box .batchChange {
  display: inline-block;
  color: #999;
  font-size: 14px;
  cursor: pointer;
}
i {
  font-size: 16px;
  color: #999;
}
.message {
  color: #666;
  font-size: 14px;
  text-align: center;
  margin-bottom: 10px;
}
.message .sign {
  font-size: 12px;
  color: #999;
  margin-right: 2px;
  font-style: normal;
}
.message span {
  display: inline-block;
  text-align: right;
  width: 70px;
}
.message span:last-child {
  color: #e6a23c;
  text-align: left;
  font-size: 20px;
  font-weight: bold;
}
</style>
